/* GeoDist.do (STATA)
	Construct GeoDist data.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;

cap log close;
log using GeoDist, replace;

/* Set local variables */

local directory = "../../Data/GeoDist";


/* Load data */

u iso_o iso_d dist using "`directory'/dist_cepii", clear;

/* Rename variables */

rename iso_o country;
rename iso_d counterpart;

/* Fix variables */

foreach var of varlist country counterpart {;
	replace `var' = "COD" if `var'=="ZAR";	/* Democratic Republic of the Congo */
	replace `var' = "PSE" if `var'=="PAL";	/* West Bank and Gaza = Palestine */
	replace `var' = "ROU" if `var'=="ROM";	/* Romania */
	replace `var' = "SRB" if `var'=="YUG";	/* Serbia = Yugoslavia */
	replace `var' = "TLS" if `var'=="TMP";	/* Timor-Leste = East Timor */
};

/* Convert to 1,000 km */

replace dist = dist/1e3;

/* Label variables */

label var country		"Investor country";
label var counterpart	"Issuer country by nationality";

label var dist			"Simple distance (1,000 km)";

/* Save data */

sort country counterpart;

save GeoDist, replace;

log close;
